﻿using System;
using System.Collections.Generic;
using System.Text;

using System.Windows.Forms;
using System.Collections;
using System.Runtime.InteropServices;

using SuperMapLib;

namespace JR_RouteAlarm
{
    class Utility
    {
        /*定数*/
        public const string ROUTE_FIELD = "SmUserId";
        public const string FEATURE = "feature_cd";
        public const string DAIBUN = "daibun_cd";
        public const string TSUUSHO = "tsuusho_cd";
        public const string BUFFER_TITLE = "バッファ";
        public const float BUFFER_ALARM_DISTANCE = 11F;
        //public const int BUFFER_ALARM_SMOOTH = 4;
        public const int MAX_UP_DOWN_DISTANCE = 50;
        //public const int MAX_ROUTE_PART_COUNT = 3000;
        //public const int PRECISION = 2;

        /*変数*/
        public static Hashtable routeLnWithBfr = null;
        public static Hashtable routeFtrWithLn = null;
        public static string datasourceAlias = string.Empty;
        public soDataSource objSource = null;
        private AxSuperMapLib.AxSuperWorkspace superWksp = null;
        private string SDBPath = String.Empty;

        public Utility(AxSuperMapLib.AxSuperWorkspace superWksp, string SDBPath)
        {
            this.superWksp = superWksp;
            this.SDBPath = SDBPath;
            InitializeSource();
            SetHashPairInfo();
        }

        private void InitializeSource()
        {
            objSource = superWksp.OpenDataSource(
                SDBPath, datasourceAlias, seEngineType.sceSDBPlus, false);
            if (objSource == null)
            {
                throw new Exception("Initialize datasource failed!");
            }
            else
            {
                //
            }
        }

        private void SetHashPairInfo()
        {
            routeLnWithBfr = new Hashtable();
            routeFtrWithLn = new Hashtable();
        }

        public void ReleaseMemory()
        {
            Marshal.ReleaseComObject(objSource);
            objSource = null;

            superWksp.Close();

            MessageBox.Show("Release memory OK!");
        }
    }
}
